package com.lagou.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;


@Activate(group = {CommonConstants.CONSUMER,CommonConstants.PROVIDER})
public class TransportIpFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Object ip = RpcContext.getContext().getAttachment("ip");
        if(ip != null) {
            System.out.println("请求的ip地址是：" + ip);
            System.out.println("RpcContext的ip地址是：" + RpcContext.getContext().getRemoteHost());
        }else
            System.out.println("ip null");
        return invoker.invoke(invocation);
    }
}
